if (typeof gxc == "undefined") {
	var gxc = {};
}

// document初始化
jQuery(function() {
	gxc.dialog.reLocatePromp();
	jQuery(window).resize(function() {
		gxc.dialog.reLocatePromp();
	});
})

/**
 * id为每个dialog的序号，递增
 */
gxc.dialog = {
	id : 1
};

gxc.dialog.hidePrompt = function(id) {
	jQuery("#" + id).slideToggle("fast", function() {
		jQuery("#" + id).remove();
	});
}

gxc.dialog.prompt = function(text, timeout) {

	var div_id = gxc.dialog.id++;

	if (jQuery("#gxc_promp_area").length < 1) {
		jQuery("body").append("<div id='gxc_promp_area'></div>");
		gxc.dialog.reLocatePromp();
	}
	var htmlString = "<div class='gxc_promp_item' id='" + div_id
			+ "' style='display: none;'>";
	htmlString += text;
	htmlString += "</div>";

	jQuery("#gxc_promp_area").append(htmlString);
	jQuery("#" + div_id).slideToggle("fast");

	// 设置timeout时间后隐藏
	var promp_timeout = 3000;
	if (typeof timeout == "number") {
		promp_timeout = timeout;
	}
	setTimeout(function() {
		gxc.dialog.hidePrompt(div_id);
	}, promp_timeout);
}

gxc.dialog.reLocatePromp = function() {
	var width = document.documentElement.clientWidth;
	var div_width = jQuery("#gxc_promp_area").width();
	var offset_left = width / 2 - div_width / 2;
	jQuery("#gxc_promp_area").css("left", offset_left);
}

gxc.dialog.createModal = function(dialogId, dialogTitle, innerSrc, width,
		height, callback) {
	var str = "<div id='"
			+ dialogId
			+ "' title='"
			+ dialogTitle
			+ "' class='gxc_modal_dialog'><iframe frameborder='no' border='no' src='"
			+ innerSrc + "'></iframe></div>";
	jQuery("body").append(str);
	jQuery("#" + dialogId).dialog({
		modal : true,
		width : width,
		height : height,
		close : function(event, ui) {
			jQuery("#" + dialogId).remove();
			if (typeof callback == "function") {
				callback();
			}
		}
	});
}

gxc.dialog.closeModal = function() {
	jQuery(".gxc_modal_dialog").dialog("destroy");
}
